shell_integration/macOS/FileProviderExt: Adapt to API changes in NextcloudFileProvide...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 4 Dec 2024 08:34:57 +0000 (16:34 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 6 Feb 2025 11:24:09 +0000 (12:24 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+Thumbnailing.swift
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift

index 2a7e5d8e51489bdcc5e2dc20bc3656474201708e..68a3981f3c1d41940ec87fd4693ddb76d5b51b7c 100644 (file)
@@ -107,14 +107,25 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte
     @objc func setupDomainAccount(
         user: String, userId: String, serverUrl: String, password: String
     ) {
+        let account = Account(user: user, id: userId, serverUrl: serverUrl, password: password)
+        guard account != ncAccount else { return }
+
         Task {
-            let authTestNcKit = NextcloudKit()
-            authTestNcKit.setup(user: user, userId: userId, password: password, urlBase: serverUrl)
+            ncKit.appendSession(
+                account: account.ncKitAccount,
+                urlBase: serverUrl,
+                user: user,
+                userId: userId,
+                password: password,
+                userAgent: "Nextcloud-macOS/FileProviderExt",
+                nextcloudVersion: 25,
+                groupIdentifier: ""
+            )
             var authAttemptState = AuthenticationAttemptResultState.connectionError // default
 
             // Retry a few times if we have a connection issue
             for authTimeout in AuthenticationTimeouts {
-                authAttemptState = await authTestNcKit.tryAuthenticationAttempt()
+                authAttemptState = await ncKit.tryAuthenticationAttempt(account: account)
                 guard authAttemptState == .connectionError else { break }
 
                 Logger.fileProviderExtension.info(
@@ -146,22 +157,12 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte
             }
 
             Task { @MainActor in
-                let newNcAccount =
-                    Account(user: user, id: userId, serverUrl: serverUrl, password: password)
-                guard newNcAccount != ncAccount else { return }
-                ncAccount = newNcAccount
-                ncKit.setup(
-                    account: newNcAccount.ncKitAccount,
-                    user: newNcAccount.username,
-                    userId: newNcAccount.id,
-                    password: newNcAccount.password,
-                    urlBase: newNcAccount.serverUrl,
-                    userAgent: "Nextcloud-macOS/FileProviderExt",
-                    nextcloudVersion: 25,
-                    delegate: nil) // TODO: add delegate methods for self
-                
+                ncAccount = account
                 changeObserver = RemoteChangeObserver(
-                    remoteInterface: ncKit, changeNotificationInterface: self, domain: domain
+                    account: account,
+                    remoteInterface: ncKit,
+                    changeNotificationInterface: self,
+                    domain: domain
                 )
                 ncKit.setup(delegate: changeObserver)
                 signalEnumeratorAfterAccountSetup()
index 0c76325564ca6b09a3f126ad8d21c677e387ceb5..e1eb24caaa2272f128c318830a276730799c4add 100644 (file)
@@ -29,9 +29,15 @@ extension FileProviderExtension: NSFileProviderThumbnailing {
         ) -> Void,
         completionHandler: @escaping (Error?) -> Void
     ) -> Progress {
+        guard let ncAccount else {
+            completionHandler(NSFileProviderError(.notAuthenticated))
+            return Progress()
+        }
+
         return NextcloudFileProviderKit.fetchThumbnails(
             for: itemIdentifiers,
             requestedSize: size,
+            account: ncAccount,
             usingRemoteInterface: self.ncKit,
             perThumbnailCompletionHandler: perThumbnailCompletionHandler,
             completionHandler: completionHandler
index db5eda2d50beb005c7a79a6a31cb907df6442488..58b3f1d81f196fe8ae54bb607398fcb1a664df4e 100644 (file)
@@ -20,7 +20,7 @@ import OSLog
 
 @objc class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension {
     let domain: NSFileProviderDomain
-    let ncKit = NextcloudKit()
+    let ncKit = NextcloudKit.shared
     let appGroupIdentifier = Bundle.main.object(forInfoDictionaryKey: "SocketApiPrefix") as? String
     var ncAccount: Account?
     var changeObserver: RemoteChangeObserver?
@@ -104,7 +104,7 @@ import OSLog
         request _: NSFileProviderRequest,
         completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void
     ) -> Progress {
-        if ncAccount == nil {
+        guard let ncAccount else {
             Logger.fileProviderExtension.error(
                 """
                 Not fetching item for identifier: \(identifier.rawValue, privacy: .public)
@@ -112,7 +112,12 @@ import OSLog
                 """
             )
             completionHandler(nil, NSFileProviderError(.notAuthenticated))
-        } else if let item = Item.storedItem(identifier: identifier, remoteInterface: ncKit) {
+            return Progress()
+        }
+
+        if let item = Item.storedItem(
+            identifier: identifier, account: ncAccount, remoteInterface: ncKit
+        ) {
             completionHandler(item, nil)
         } else {
             completionHandler(nil, NSFileProviderError(.noSuchItem))
@@ -147,7 +152,7 @@ import OSLog
             return Progress()
         }
 
-        guard ncAccount != nil else {
+        guard let ncAccount else {
             Logger.fileProviderExtension.error(
                 """
                 Not fetching contents for item: \(itemIdentifier.rawValue, privacy: .public)
@@ -159,7 +164,9 @@ import OSLog
             return Progress()
         }
 
-        guard let item = Item.storedItem(identifier: itemIdentifier, remoteInterface: ncKit) else {
+        guard let item = Item.storedItem(
+            identifier: itemIdentifier, account: ncAccount, remoteInterface: ncKit
+        ) else {
             Logger.fileProviderExtension.error(
                 """
                 Not fetching contents for item: \(itemIdentifier.rawValue, privacy: .public)
@@ -228,6 +235,7 @@ import OSLog
                 contents: url,
                 request: request,
                 domain: self.domain,
+                account: ncAccount,
                 remoteInterface: ncKit,
                 progress: progress
             )
@@ -283,7 +291,9 @@ import OSLog
             return Progress()
         }
 
-        guard let existingItem = Item.storedItem(identifier: identifier, remoteInterface: ncKit) else {
+        guard let existingItem = Item.storedItem(
+            identifier: identifier, account: ncAccount, remoteInterface: ncKit
+        ) else {
             Logger.fileProviderExtension.error(
                 "Not modifying item: \(ocId, privacy: .public) as item not found."
             )
@@ -331,7 +341,7 @@ import OSLog
             "Received delete request for item: \(identifier.rawValue, privacy: .public)"
         )
 
-        guard ncAccount != nil else {
+        guard let ncAccount else {
             Logger.fileProviderExtension.error(
                 "Not deleting item \(identifier.rawValue, privacy: .public), account not set up yet"
             )
@@ -340,7 +350,9 @@ import OSLog
             return Progress()
         }
 
-        guard let item = Item.storedItem(identifier: identifier, remoteInterface: ncKit) else {
+        guard let item = Item.storedItem(
+            identifier: identifier, account: ncAccount, remoteInterface: ncKit
+        ) else {
             Logger.fileProviderExtension.error(
                 "Not deleting item \(identifier.rawValue, privacy: .public), item not found"
             )
@@ -376,6 +388,7 @@ import OSLog
 
         return Enumerator(
             enumeratedItemIdentifier: containerItemIdentifier,
+            account: ncAccount,
             remoteInterface: ncKit,
             domain: domain,
             fastEnumeration: config.fastEnumerationEnabled,